package com.wish.algorithm;

/**
 * Created by suliucheng on 2021/4/15 21:36
 * Directions:利用递归 计算 数的阶乘 比如计算
 * 10！
 * 1！+2！+3！+4！+...+10!
 * 1/1! +1/2! + ...+1/10！
 */
public class RecursionOfFactorial {
    /**
     * 计算 10！
     * @return
     */
    public static Double calculate01(int num){
        if(num == 1){
            return 1.0;
        }
        return calculate01(num-1)* num;
    }

    /**
     * 计算 1！+2！+3！+4！+...+10!
     * @param num
     * @return
     */
    public static Double calculate02(int num){
        Double result = 0.0;
        for (int i = 1; i <= num; i++) {
            result+= calculate01(i);
        }
        return result;
    }

    /**
     * 1/1! +1/2! + ...+1/10！
     * @param num
     * @return
     */
    public static Double calculate03(int num){
        Double result = 0.0;
        for (int i = 1; i <= num; i++) {
            result+= 1/calculate01(i);
        }
        return result;
    }
}
